package com.zcrain.aspectjdemo;

import android.util.Log;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;

/**
 * @Author:CWQ
 * @DATE:2023/12/6
 * @DESC:
 */
@Aspect
public class TrackEventAspectj {
    private static final String TAG = "TrackEventAspectj";

    @Around("execution(@com.zcrain.aspectjdemo.TrackEvent * *(..))")
    public void trackEvent(ProceedingJoinPoint joinPoint){
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();

        TrackEvent trackEvent = signature.getMethod().getAnnotation(TrackEvent.class);
        String eventName = trackEvent.eventName();
        String eventId = trackEvent.eventId();

        Log.d(TAG, "trackEvent: name:" + eventName + " id:" + eventId);

        try {
            joinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }
}
